const Router = require('koa-router')
const { sendRequest } = require('../../lib/utils/aiqian')
const router = new Router({ prefix: '/test' })

router.post('/', async (ctx, next) => {
  const { body } = ctx.request
  const url = ctx.query.url ? decodeURIComponent(ctx.query.url) : ''
  if (!url) {
    ctx.body = {
      code: 200,
      message: '无效的url'
    }
    return
  }

  const result = await sendRequest(body, url)

  console.log(result)

  ctx.body = {
    code: 200,
    message: 'ok',
    data: result
  }
})

module.exports = router
